﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.RequestContext", ServerTypeId="{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}")]
    internal class RequestContext : ClientObject
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public RequestContext(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public static RequestContext GetCurrent(ClientRuntimeContext Context)
        {
            object obj2 = null;
            if (!Context.StaticObjects.TryGetValue("Microsoft$SharePoint$SPContext$Current", out obj2))
            {
                obj2 = new RequestContext(Context, new ObjectPathStaticProperty(Context, "{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}", "Current"));
                Context.StaticObjects["Microsoft$SharePoint$SPContext$Current"] = obj2;
            }
            return (RequestContext) obj2;
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag)
            {
                string str = peekedName;
                if (str == null)
                {
                    return flag;
                }
                if (!(str == "Web"))
                {
                    if (str == "Site")
                    {
                        flag = true;
                        reader.ReadName();
                        this.Site.FromJson(reader);
                    }
                    return flag;
                }
                flag = true;
                reader.ReadName();
                this.Web.FromJson(reader);
            }
            return flag;
        }

        [Remote]
        public Microsoft.SharePoint.Client.Site Site
        {
            get
            {
                object obj2;
                if (base.ObjectData.ClientObjectProperties.TryGetValue("Site", out obj2))
                {
                    return (Microsoft.SharePoint.Client.Site) obj2;
                }
                Microsoft.SharePoint.Client.Site site = new Microsoft.SharePoint.Client.Site(base.Context, new ObjectPathProperty(base.Context, base.Path, "Site"));
                base.ObjectData.ClientObjectProperties["Site"] = site;
                return site;
            }
        }

        [Remote]
        public Microsoft.SharePoint.Client.Web Web
        {
            get
            {
                object obj2;
                if (base.ObjectData.ClientObjectProperties.TryGetValue("Web", out obj2))
                {
                    return (Microsoft.SharePoint.Client.Web) obj2;
                }
                Microsoft.SharePoint.Client.Web web = new Microsoft.SharePoint.Client.Web(base.Context, new ObjectPathProperty(base.Context, base.Path, "Web"));
                base.ObjectData.ClientObjectProperties["Web"] = web;
                return web;
            }
        }
    }
}

